﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Induction.FinalTest
{
    public partial class Report : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GeneralLinqToSQLDataContext dc = new GeneralLinqToSQLDataContext();
            //var getLastID =
            //    (from cust in dc.Customers
            //    select cust).AsEnumerable();
            //string lastCustID = getLastID.CustomerNumber;
            var c =
                    (from lc in dc.Customers
                    join co in dc.Countries on lc.DefaultCurrency equals co.CountryID
                    //where lc.CustomerNumber == lastCustID
                    select new
                    {
                        co.Currency,
                        co.CountryName,
                        lc.CustomerName,
                        lc.CustomerNumber,
                        lc.City,
                        lc.Address1,
                        lc.Address2,
                        lc.Address3,
                        lc.Website,
                        lc.PhoneNumber,
                        lc.FaxNumber,
                        lc.State,
                        lc.Email,
                        lc.PostCode,
                        lc.Status
                    }).AsEnumerable().Last();
            CustomerNameLabel.Text = c.CustomerName;
            CustomerNumberLabel.Text = c.CustomerNumber;
            CityLabel.Text = c.City;
            Add1Label.Text = c.Address1;
            Add2Label.Text = c.Address2;
            Add3Label.Text = c.Address3;
            PhoneLabel.Text = c.PhoneNumber;
            FaxLabel.Text = c.FaxNumber;
            EmailLabel.Text = c.Email;
            WebsiteLabel.Text = c.Website;
            StateLabel.Text = c.State;
            DefCurrencyLabel.Text = c.Currency;
            CountryLabel.Text = c.CountryName;
            PostCodeLabel.Text = c.PostCode;
            if (c.Status.Equals("0"))
            {
                StatusLabel.Text = "Non Active";
            }
            else
            {
                StatusLabel.Text = "Active";
            }
        }

        protected void AddNew_Click(object sender, EventArgs e)
        {
            Response.Redirect("Index.aspx");
        }

        protected void DisplayDataInList_Click(object sender, EventArgs e)
        {
            Response.Redirect("CustomerDataList.aspx");
        }
    }
}